import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author pizhihui
 * @date 2024-02-01 15:39
 */
public class RedisPartitionTest {

    public static void main(String[] args) throws IOException {


        String path = "/Users/pizhihui/ProjectsIdea/code-bigdata/code-00java/src/main/resources/4.txt";
        List<String> strings = Files.readAllLines(Paths.get(path));

        Map<String, List<Integer>> mapMaster = new HashMap<>();
        Map<String, List<Integer>> mapSlave = new HashMap<>();
        Map<String, List<Integer>> all = new HashMap<>();
        for (String string : strings) {
            if (StringUtils.isBlank(string)) {
                continue;
            }

            String[] s1 = null;
            String slave = null;
            try {
                String[] s = string.split(" ");
                String id = s[0];
                String uris = s[1];
                slave = s[2];
                s1 = uris.split("@")[0].split(":");
            } catch (Exception e) {
                System.out.println("error: " + string);
            }
            if (null == s1) {
                continue;
            }

            String ip = s1[0];
            String port = s1[1];
            if (StringUtils.isNotBlank(slave)) {
                if (StringUtils.equals("master", slave)) {
                    mapMaster.computeIfAbsent(ip, k -> new ArrayList<>()).add(Integer.parseInt(port));
                } else {
                    mapSlave.computeIfAbsent(ip, k -> new ArrayList<>()).add(Integer.parseInt(port));
                }
                all.computeIfAbsent(ip, k -> new ArrayList<>()).add(Integer.parseInt(port));
            }

            System.out.println("end.........ssss.");

        }
        System.out.println(mapMaster.keySet());
        System.out.println(mapSlave.keySet());
        System.out.println(all.keySet());
        System.out.println("end..........");
    }


}
